<%--@elvariable id="dictName" type="java.lang.String"--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%@include file="../includes/common.jsp" %>
    <title>评论内容</title>
<body>
<div id="mainContent" class="easyui-panel" data-options="fit:true" style="padding: 10px">
    <form class="form-inline">
        评论分数<input type="text" name="commentScore" id="commentScore" value=""/>
        <a class="btn btn-primary" onclick="query()">查询</a>
        <a class="btn btn-primary" onclick="delComment()">删除</a>
    </form>
    <table id="dataTable"></table>
    <div id="dataEdit" closed="true" modal="true" style="overflow: hidden">
        <iframe style="width: 100%;height: 100%"
                id="contentFrame"
                name="contentFrame"
                marginheight="0"
                marginwidth="0"
                frameborder="0" src=""
                allowTransparency="true">
        </iframe>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    function query() {
        var commentScore=$("#commentScore").val().trim();
        if(commentScore==null || commentScore==""){
            commentScore=0
        }
        listOption.url = basePath + "comment/listScormComment";
        listOption.data = "scormId=" + ${scormId}+"&commentScore="+commentScore;
        listOption.pageNumber = 1;
        loadData(listOption);
    }

    function initDataGrid() {
        $('#dataTable').datagrid({
            title:'评论内容',
            pagination: true,
            fitColumns: true,
            columns: [
                [
                    {field: 'id', title: "&nbsp<input id='checkAll' type='checkbox' onclick='selectAll()'/>", align: 'center', width: 50},
                    {field: 'commentScore', title: '评论分数', sortable: true, align: 'center', width: 80},
                    {field: 'commentTime', title: '评论时间', sortable: true, align: 'center', width: 150},
                    {field: 'commentContent', title: '评论内容', align: 'center', width: 200},
                    {field: 'commentUser', title: '评论者', align: 'center', width: 100},
                    {field: 'operate', title: '操作', align: 'center', width: 80}
                ]
            ],
            sortName: "",
            sortOrder: "asc",
            onSortColumn: onSortColumn
        });
    }

    function onSortColumn(sortColumn, sortDirection) {
        switch (sortColumn) {
            case "dictCode":
                sortColumn = "dict_code";
                break;
            case "dictValue":
                sortColumn = "dict_value";
                break;
        }
        onSortColumnDefault(sortColumn, sortDirection);
    }

    function format(data) {
        data.resultList = queryFormat(data.resultList);
        return data;
    }

    function queryFormat(temp) {
        var rowDataList = [];
        for (var i in temp) {
            idBtn = "&nbsp;<input type='checkbox' name='deleteUserCheckBox' id='" + temp[i].id + "' value='" + temp[i].id + "'\">&nbsp;";
            viewBtn = "&nbsp;<a onclick='edit(\"" + temp[i].id + "\")'>编辑</a>&nbsp;";
            temp[i].id = idBtn;
            temp[i].operate = viewBtn;
            rowDataList.push(temp[i]);
        }
        return rowDataList;
    }
    function edit(id){
        $("#contentFrame")[0].contentWindow.document.write("");
        $("#contentFrame").attr("src", basePath + "comment/editCommentDo?id=" + id);
        $('#dataEdit').dialog({
            title: '修改评价信息',
            height: 460,
            width: 600
        })
        $('#dataEdit').dialog('open');
    }


    function delComment() {
        var ids = "";
        var value;
        var flag = 0;
        var allBox = $("[name='deleteUserCheckBox']");
        for (var i = 0; i < allBox.length; i++) {
            value = allBox[i].getAttribute("value");
            if ($("#" + value).attr("checked") == "checked") {
                if ("${myLoginId}" == value) {
                    $.messager.alert("系统提示", "不可删除自己");
                    return;
                }
                flag = 1;
                ids += value + ",";
            }
        }
        if (flag == 0) {
            $.messager.alert("系统提示", "请选择一条数据!");
            return;
        }
        $.messager.confirm("系统提示", "确认删除吗？", function (r) {
            if (r) {
                $.ajax({
                    url: basePath + "comment/delComment?ids=" + ids,
                    dataType: "json",
                    type: "DELETE",
                    success: function () {
                        $.messager.alert("成功", "删除成功！", "", function () {
                            query();
                        })
                    },
                    error: doError
                })
            }
        })
        }
    function selectAll() {
        if ($("#checkAll").attr("checked") == "checked") {
            $("[name='deleteUserCheckBox']").attr("checked", true);
        } else {
            $("[name='deleteUserCheckBox']").attr("checked", false);
        }
    }

    $(function () {
        initDataGrid();
        query();
    })
</script>